home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / zfzlib.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  2.9 KB  |  107 lines

  1. /* Copyright (C) 1995, 2000 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: zfzlib.c,v 1.3 2000/09/19 19:00:54 lpd Exp $ */
  20. /* zlib and Flate filter creation */
  21. #include "ghost.h"
  22. #include "oper.h"
  23. #include "idict.h"
  24. #include "strimpl.h"
  25. #include "spdiffx.h"
  26. #include "spngpx.h"
  27. #include "szlibx.h"
  28. #include "idparam.h"
  29. #include "ifilter.h"
  30. #include "ifrpred.h"
  31. #include "ifwpred.h"
  32.  
  33. /* Common setup for zlib (Flate) filter */
  34. private int
  35. filter_zlib(i_ctx_t *i_ctx_p, stream_zlib_state *pzls)
  36. {
  37.     os_ptr op = osp;
  38.     int code = 0;
  39.  
  40.     (*s_zlibE_template.set_defaults)((stream_state *)pzls);
  41.     if (r_has_type(op, t_dictionary))
  42.     code = dict_int_param(op, "Effort", -1, 9, -1, &pzls->level);
  43.     return code;
  44. }
  45.  
  46. /* <source> zlibEncode/filter <file> */
  47. /* <source> <dict> zlibEncode/filter <file> */
  48. private int
  49. zzlibE(i_ctx_t *i_ctx_p)
  50. {
  51.     stream_zlib_state zls;
  52.     int code = filter_zlib(i_ctx_p, &zls);
  53.  
  54.     if (code < 0)
  55.     return code;
  56.     return filter_write(i_ctx_p, 0, &s_zlibE_template, (stream_state *)&zls, 0);
  57. }
  58.  
  59. /* <target> zlibDecode/filter <file> */
  60. /* <target> <dict> zlibDecode/filter <file> */
  61. private int
  62. zzlibD(i_ctx_t *i_ctx_p)
  63. {
  64.     stream_zlib_state zls;
  65.  
  66.     (*s_zlibD_template.set_defaults)((stream_state *)&zls);
  67.     return filter_read(i_ctx_p, 0, &s_zlibD_template, (stream_state *)&zls, 0);
  68. }
  69.  
  70. /* <source> FlateEncode/filter <file> */
  71. /* <source> <dict> FlateEncode/filter <file> */
  72. private int
  73. zFlateE(i_ctx_t *i_ctx_p)
  74. {
  75.     stream_zlib_state zls;
  76.     int code = filter_zlib(i_ctx_p, &zls);
  77.  
  78.     if (code < 0)
  79.     return code;
  80.     return filter_write_predictor(i_ctx_p, 0, &s_zlibE_template,
  81.                   (stream_state *)&zls);
  82. }
  83.  
  84. /* <target> FlateDecode/filter <file> */
  85. /* <target> <dict> FlateDecode/filter <file> */
  86. private int
  87. zFlateD(i_ctx_t *i_ctx_p)
  88. {
  89.     stream_zlib_state zls;
  90.  
  91.     (*s_zlibD_template.set_defaults)((stream_state *)&zls);
  92.     return filter_read_predictor(i_ctx_p, 0, &s_zlibD_template,
  93.                  (stream_state *)&zls);
  94. }
  95.  
  96. /* ------ Initialization procedure ------ */
  97.  
  98. const op_def zfzlib_op_defs[] =
  99. {
  100.     op_def_begin_filter(),
  101.     {"1zlibEncode", zzlibE},
  102.     {"1zlibDecode", zzlibD},
  103.     {"1FlateEncode", zFlateE},
  104.     {"1FlateDecode", zFlateD},
  105.     op_def_end(0)
  106. };
  107.